<?php
$pharmacy_id = $_SESSION['acc_id'];
$product_name = $product_type = $country_id = $price = $laboratory = $product_description = "";
$count_arry =  $price_array = $labor_array = $pid_array = array();
$sql = "SELECT tblproduct.*,tblproduct_in_pharmacy.* FROM tblproduct,tblproduct_in_pharmacy WHERE tblproduct.id=$id AND tblproduct.id = tblproduct_in_pharmacy.product_id AND tblproduct_in_pharmacy.pharmacy_id = $pharmacy_id";
$result = mysql_query($sql);
$result1 = mysql_query($sql);
while($row_c = mysql_fetch_assoc($result1)){
		$count_arry[] = $row_c['country_id'];	
		$price_array[] = $row_c['price'];
		$labor_array[] = $row_c['laboratory'];
		$pid_array[] = $row_c['pid'];
	}
$row = mysql_fetch_assoc($result);
if(dbNumRows($result)){
extract($row);
}
?>
<script src='jquery.js' type="text/javascript"></script>
<script src='documentation.js' type="text/javascript"></script>
<script src='jquery.MultiFile.js' type="text/javascript" language="javascript"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo W_ROOT;?>/jscripts/initialeditor.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.delcount').click(function(){
	var id = $(this).attr('id');
	
	if($(".selectCon").length>1){
		$.ajax({
				type: "GET",
				url: "process.php",
				data: "action=deletet_count&pid=" + id,
				success: function(message){
					$('.'+id).remove();
				}
		});
	}else{
		alert('You cannot delete the last one!');
		$('.delcount').addClass('displayNo');
	}
	
});
});
</script>
<style type="text/css">
#backgroundPopup{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:100%;  
width:100%;  
top:0;  
left:0;  
background:#000000;  
border:1px solid #cecece;  
z-index:1;  
}  
#popuptext{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:650px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px;  
font-size:13px;  
} 
#popupCategory{  
display:none;  
position:fixed;  
_position:absolute; /* hack for internet explorer 6*/  
height:400px;  
width:635px;  
background:#FFFFFF;  
border:2px solid #cecece;  
z-index:2;  
padding:12px; 
overflow:scroll;
overflow-x: hidden; 
} 
#popuptextClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
#popupcateClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
cursor:pointer;
}
</style>
<script src="popup.js" type="text/javascript"></script>
<table id="tblAddPro" cellpadding="5" cellspacing="5" border="0" width="100%" height="100%;">
	<tr>
    <td>Select Category</td>
    <td width="10">:</td>
    <td><a style="color:#00F; text-decoration:underline" href="#top" id="selectCate"><em>Select Category</em></a>
    <div id="popupCategory">
    <a id="popupcateClose">Save</a><br />
    <?php
	include('category.php');
	?>
    </div>    
    </td>
    </tr>
	<tr>
    <td>Product Name</td>
    <td width="10">:</td>
    <td><input type="text" name="new_proname" value="<?php echo $product_name;?>" /></td>
    </tr>
    <tr>
    <td>Product Type</td>
    <td width="10">:</td>
    <td>
    <select name="selectType" id="selectbox" style="width:415px;">
    <option value="">select type</option>
    <option value="Tablet" <?php echo($product_type=='Tablet')?' selected="selected"':''?>>Tablet</option>  
    <option value="Liquid" <?php echo($product_type=='Liquid')?' selected="selected"':''?>>Liquid</option>  
    <option value="Plaster"<?php echo($product_type=='Plaster')?' selected="selected"':''?>>Plaster</option>  
    <option value="Powder" <?php echo($product_type=='Powder')?' selected="selected"':''?>>Powder</option>   
    <option value="Other"  <?php echo($product_type=='Other')?' selected="selected"':''?>>Other</option>    
    </select>
    </td>
    </tr>  
 	<?php
	foreach($count_arry as $key => $value)
	{
		$country_id = $value;
		$price = $price_array[$key];
		$laboratory = $labor_array[$key];
		$pid = $pid_array[$key];
	?>    
    <tr class="<?php echo $pid?>">
    <td>Made In <a style="color:#F00; cursor:pointer;" id="<?php echo $pid?>" class="delcount"><strong>[x]</strong></a></td>
    <td width="10">:</td>
    <td>
    <select name="selectCoun[]" id="selectbox" style="width:270px;" class="selectCon">
    <option value="">select country</option>
    <?php
	$sql_coun = "SELECT id,country_name FROM tblcountries";
	$result_coun = mysql_query($sql_coun);
	while($row_coun = mysql_fetch_assoc($result_coun)){
	?>
    <option value="<?php echo $row_coun['id']?>" <?php echo($row_coun['id']==$country_id)?' selected="selected"':''?>><?php echo $row_coun['country_name']?></option>
    <?php	
	}
	?>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    Price($) : <input type="text" name="price[]" style="width:80px;" value="<?php echo $price;?>" class="txtprice" />
    </td>
    </tr>
    <tr class="<?php echo $pid?>">
    <td>Laboratory</td>
    <td width="10">:</td>
    <td><input type="text" name="laboratory[]" value="<?php echo $laboratory?>" class="labor" />
            <input type="hidden" name="hidpid[]" value="<?php echo $pid;?>" />
    </td>
    </tr>
    <?php
	}
	?>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><img src="<?php echo W_ROOT;?>/images/add_icon.jpg" border="0" /> 
        <a style="color:#00F; text-decoration:underline" href="#" id="clicktoadd" onclick="addCountry($(this)); return false;"><em>Add another Country</em></a></td>
    </tr>    
    <tr>
    <td valign="top">Images</td>
    <td width="10" valign="top">:</td>
    <td><input type="file" class="multi" name="imagefile[]" size="53"/><br />
    <em style="color:#666;">You can add more than one time</em>
    </td>
    </tr>  
    </tr>
	<?php
	$sql_img = "SELECT * FROM tblimage WHERE product_id =".$id;
	$result_img = mysql_query($sql_img);
	if(dbNumRows($result_img)){
	?>
<tr class="imageitem"> 
   <td width="15%" height="30" align="left" valign="top"></td>
   <td width="5%" align="left" valign="top"></td>
   <td width="80%" align="left" style="padding-bottom:10px;">
   <?php
   	while( $row_img = mysql_fetch_assoc($result_img)){
		if($row_img['product_id'] !=""){
   ?>
   <div style="float:left;" class="div<?php echo $row_img['id'];?>">
    <img src="images/<?php echo $row_img['thumbnail'];?>" class="border" />
    </div>
    <?php
		}//end if
	}//end if
	}//end while
	?>
	</td>
</tr>
    <tr>
    <td valign="top">Description</td>
    <td valign="top">:</td>
    <td>
    <a href="#" id="displaypopup" style="color:#03F;">Click to insert Description</a>
    <div id="popuptext">
    <a id="popuptextClose">Save</a><br />
    <em style="color:#666;">Please input product's description with the detail...</em><br />
    <textarea name="txtdesc" id="txtdesc" rows="20" style="height:350px;"><?php echo stripslashes($product_description);?></textarea>
    </div>
    </td>
    </tr>
    <tr>
    <td colspan="3" align="center" style="padding-top:30px; padding-bottom:20px;">
		<input type="button" name="btnsubmit" value="Save" onclick="checkSellerform();" />&nbsp;&nbsp;&nbsp;
        <input type="button" value="Cancel" onclick="window.location.href='index.php'" />
        <input type="hidden" name="hidid" value="<?php echo $id;?>" />
    </td>
    </tr>
</table>
<script type="text/javascript">
	var addCountryHtml = "<tr>" + $("#tblAddPro tr:eq(3)").html() + "</tr><tr>" + $("#tblAddPro tr:eq(4)").html() + "</tr>";
	function addCountry(aLink){
		aLink.parent().parent().before(addCountryHtml);
		$('.txtprice:last').val('');
		$('.labor:last').val('');
		$('.selectCon:last').val('');
	}
</script>
<div id="backgroundPopup"></div> 